package com.yq.design.command;

/**
 * @ClassName RemoteController
 * @Description TODO
 * @Author yaoqiang
 * @Date 2021/8/20 16:05
 * @Version 1.0
 */
public class RemoteController {
    //开按钮的命令组
    Command[] onCommands;
    Command[] offCommands;

    //执行撤销
    Command undoCommand;

    public RemoteController() {
        onCommands=new Command[5];
        offCommands=new Command[5];

        for (int i=0;i<5 ;i++){
            onCommands[i]=new noCommand();
            offCommands[i]=new noCommand();
        }
    }

    public void setCommand(int no, Command onCommand,Command offCommand){
        onCommands[no]=onCommand;
        offCommands[no]=offCommand;
    }
    public void onButton(int no){
        onCommands[no].execute();
        undoCommand=onCommands[no];
    }
    public void offButton(int no){
        offCommands[no].execute();
        undoCommand=offCommands[no];
    }

    public void undoButton(){
        undoCommand.undo();
    }
}
